	
	<div id="page-content">
			<div class="col-lg-12">
		        <div class="panel">
		            <div class="panel-heading">
		                <h3 class="panel-title" style="text-align: right;">
		                	#@installPJaxGoBackBtn()
		                	添加新机构
		                </h3>
		            </div>
		            <form id="editForm" class="panel-body form-horizontal form-padding">
		            	<div class="form-group">
		                    <label class="col-md-3 control-label">父级机构</label>
		                    <div class="col-md-5">
		                        <div class="input-group mar-btm">
			                        <input type="text" id="pName" value="#(p?p.name:'根目录')" readonly class="form-control">
									<input type="hidden" id ="pId" name="sysOrg.parent_id"  value="#(p?p.id:'#root')">
									<input type="hidden" id = "orgId" name="sysOrg.id" value="#(o?o.id:'')">
			                        
			                        <span class="input-group-btn">
			                            <button class="btn btn-primary" type="button" onclick="selectOneOrg()">选择</button>
			                        </span>
			                    </div>
		                        <small class="help-block">请选择</small>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-md-3 control-label">机构类型</label>
		                    <div class="col-md-9">
		                        <input type="hidden" id="type" name="sysOrg.type" class="form-control"  value="#(type)">
		                        <input type="text" id="typeName" class="form-control"  value="#if(type=='1')公司#elseif(type=='0')部门#end" disabled="disabled">
		                    </div>
		                </div>
		                #if(type=='0')
			                <div class="form-group">
			                    <label class="col-md-3 control-label">所属子公司</label>
			                    <div class="col-md-9">
			                        <input type="hidden" id="type" name="sysOrg.parent_child_company_id" class="form-control"  value="#(parentCompany?parentCompany.id:'#root')">
			                        <input type="text" class="form-control"  value="#(parentCompany?parentCompany.name:'根目录')" disabled="disabled">
			                    </div>
			                </div>
			            #end
		                <div class="form-group">
		                    <label class="col-md-3 control-label">机构名称</label>
		                    <div class="col-md-9">
		                        <input type="text" id="orgName" name="sysOrg.name" class="form-control"  value="#(o?o.name:'')">
		                        <small class="help-block">请输入机构名称</small>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-md-3 control-label">所属区域</label>
		                    <div class="col-md-9">
		                        <input type="text" id="area" name="sysOrg.area" class="form-control"  value="#(o?o.area:'')">
		                        <small class="help-block">请输入机构名称</small>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-md-3 control-label" for="demo-textarea-input">描述信息</label>
		                    <div class="col-md-9">
		                        <textarea name="sysOrg.description" rows="9" class="form-control">#(o?o.description:'')</textarea>
		                        <small class="help-block">请输入机构的描述信息</small>
		                    </div>
		                </div>
		                <div class="form-group">
		                    <label class="col-md-3 control-label">显示顺序</label>
		                    <div class="col-md-4">
		                        <input type="text" name="sysOrg.sort" class="form-control" value="#(o?o.sort:'')">
		                        <small class="help-block">请输入机构显示顺序</small>
		                    </div>
		                </div>
		                <div class="panel-footer">
		                    <div class="row">
		                        <div class="col-sm-9 col-sm-offset-3">
		                            <button class="btn btn-warning" type="reset">重置</button>
		                            <button class="btn btn-primary" type="submit" >保存</button>
		                        </div>
		                    </div>
		                </div>
		            </form>
		        </div>
		    </div>
	</div>
	<script>
		
		function save(){
			var data = common_ajax.ajaxFunc("/admin/sys/org/save", $('#editForm').serialize(), "json", null);
			if(data.success){
				pointLion.alertMsg("保存成功!" , "success" , "small" , function(){
					location.href = ctx+'/admin/sys/org/getListPage';//跳转到列表页
				});
			}
		}
		function selectOneOrg(){
			//调用选择一个单位组件
			pointLion.selectOneOrg(function(orgNode){
				var thisId = $("#orgId").val();//主键
				if(thisId==orgNode.id){
					 layer.closeAll();
					 pointLion.alertMsg("您不能选择自己为父级节点!" , "warning" , "small" , null);
					 return;
				}
				$("#pName").val(orgNode.name);//所选单位名称
				$("#pId").val(orgNode.id);//所选单位id
			},null,null,null,null);
		}
		function valiData(pid){
			$('#editForm').bootstrapValidator({
	            fields: {
	            	"sysOrg.name": {
	                    validators: {
	                        notEmpty: {
	                            message: '*机构名称不能为空'
	                        },
	                        stringLength: {/*长度提示*/
	                            max: 25,
	                            message: '*机构名称长度必须小于25'
	                        },
	                        remote: {
	                        	type:'POST',
			                    message: '*同级别组织机构中，不允许有重名的单位！',
			                    url:ctx+'/admin/sys/org/validOrgname',
			                    data: function(validator) {
		                               return {
		                                   parentId: $('#pId').val(),
		                                   orgId:$("#orgId").val()
		                               };
		                            },
			                    delay:1000
			                }
	                    }
	                },
	                "sysOrg.sort": {
	                    validators: {
	                    	lessThan: {
	        					inclusive:true,
	        					value: 20,
	        					message: '*请输入小于20的数字'
	        				}
	                    }
	                },
	                "sysOrg.description": {
	                    validators: {
	                    	stringLength: {
	                            max: 2000,
	                            message: '*机构描述信息长度必须小于2000'
	                        }
	                    }
	                }
	            }
	        }).on("success.form.bv", function (e) {
	            save();
	            return false;//阻止表单跳转
	        });
		}
		$(document).ready(function() {
				var pid = $("#pId").val();
		    	valiData(pid);
		});
	</script>